package controller;

import com.alibaba.fastjson.JSONArray;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import util.PreAddCallback;
import util.barrageUtil;

@Controller
@RequestMapping("/barrage")
public class barrageController {

    private static String host = "47.95.229.225";
    private static int port = 6379;
    private static JedisPool pool = barrageUtil.open(host, port);
    private static Jedis jedis = pool.getResource();
    @RequestMapping(value="/addBarrage")
    @ResponseBody
    public void addBarrage(String time, String usersName, String barrageVal) {
        jedis.hset(usersName, time, barrageVal);
    }
    @RequestMapping(value="/findBarrage")
    @ResponseBody
    public String findBarrage(String time, String usersName, String callback) {
        return PreAddCallback.preAddCallback(JSONArray.toJSONString(jedis.hget(usersName, time)),callback);
    }
}


